#ifndef EVENTLOOP_EPOLLER_H
#define EVNETLOOP_EPOLLER_H

#include "Poller.h"
#include "utility/chrono.h"

#include <map>
#include <vector>

struct epoll_event;

class EPoller : public Poller
{
public:
    using EventList = std::vector<epoll_event>;
    using ChannelMap = std::map<int, Channel *>;    // <fd, Channel *>

    EPoller(Eventloop *loop);
    virtual ~EPoller();

    virtual Utility::timepoint poll(int timeout, ChannelList *activeChannels);
    virtual void update_channel(Channel *channel) override;
    virtual void remove_channel(Channel *channel) override;

private:
    void _fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
    void _update(int operation, Channel *channel);

    static constexpr int kInitEventListSize = 16;

    int  _epollfd;
    EventList _events;
    ChannelMap _channels;
};



#endif